package data.dep;

import java.util.Enumeration;
import java.util.HashMap;

import data.crawling.PageCrawler;

import websphinx.Link;
import websphinx.Page;
import websphinx.Tag;

/**
 * @deprecated
 * camera1 -> (\exists hasReview. (construction = 1 AND ease_of_use = 3) )
 * @author j55wu
 *
 */
public class ReviewCrawler extends PageCrawler{
	
	HashMap<String, String> detailedReviews= new HashMap<String, String>();

	@Override
	public boolean shouldVisit(Link l){
		return true;
	}
	
	public void visit(Page page){
		//System.out.println(page.getTitle());
		boolean find = false;
		for(Tag tag:page.getTags()){
			Enumeration<?> e = tag.enumerateHTMLAttributes();
			while(e.hasMoreElements()){
				Object attr = e.nextElement();
				if(attr.toString().equals("class")){
					if(tag.getHTMLAttribute(attr.toString()) .equals("mainContent")){
						String factors = tag.getElement().toText();
						if(!factors.contains("Average rating")){
							//no detailed ratings available
							continue;
						}
						factors = factors.substring(factors.indexOf("Construction"), factors.lastIndexOf("Owners Opinions"));
						detailedReviews.put("Construction",factors.substring(12, factors.indexOf("Features")-2));
						detailedReviews.put("Features",factors.substring(factors.indexOf("Features")+8, factors.indexOf("Image quality")-2));
						detailedReviews.put("Image quality",factors.substring(factors.indexOf("Image quality")+13, factors.indexOf("Ease of use")-2));
						detailedReviews.put("Ease of use",factors.substring(factors.indexOf("Ease of use")+11, factors.indexOf("Value for money")-2));
						detailedReviews.put("Value for money",factors.substring(factors.indexOf("Value for money")+15, factors.indexOf("Overall")-2));
						detailedReviews.put("Overall",factors.substring(factors.indexOf("Overall")+7));
						find = true;
						break;
					}
				}
			}
			if(find){
				break;
			}
		}
		//
	}
	

	
}
